#ifndef ENGINE_H
#define ENGINE_H

#define NoEditObject - 1
class	Polar;
class	Decart;
struct	Size;

enum	SkinType { Usual, Contur };
enum	GravityModeType { Radial, Direct } GravityMode = Radial;
enum	CollissionModeType { Bouncing, Merging } CollissionMode = Merging;
enum	ObjectType { Planet = 10, Star = 1000, Meteor = 2, Comet = 1, NotExist = 0 };
enum	AlertType { NoAlert, MaxObjectAmount, TooCloseToOther, ShowF1HotKey, ImpossibleLocation };
enum	MouseButtonType 
{ 
	EmptyField,
	Minimap,
	NoKey,
	OtherObject,
	TooClose,
	ToolbarAccept,
	ToolbarNextType,
	ToolbarPrevType,
	ToolbarRemove,
	ToolbarWeight
};

class Decart
{
public:
	double	x;
	double	y;
			Decart ();
			Decart (double x, double y);
			Decart (Polar place);
			~Decart ();
	double	X ();
	double	Y ();
	Decart	operator - (const Decart &place);
	Decart	operator + (const Decart &place);
	Decart	operator * (const double Coeficient);
	Decart	operator / (const double Coeficient);
	Decart	&operator += (const Decart &place);
	Decart	&operator = (const Polar &place);
	double	Distance () const;
	double	Distance (Decart place) const;
	double	Angle () const;
	void	SetRadius (double radius);
	void	CutDown (double radius);
};

class Polar
{
public:
	double	angle;
	double	radius;
			Polar ();
			Polar (double angle, double radius);
			Polar (Decart place);
			~Polar ();
	Polar	&operator = (const Decart &place);
	void	CutDown (double radius);
	void	CutAngle ();
};

class ObjectInfo
{
public:
	Decart	place;
	Decart	speed;
	double	weight;
	bool	setup;
	bool	exist;
	ObjectType type;
	Decart *tail;

			ObjectInfo ();
			~ObjectInfo ();
	double	GetSize ();
	double	FullWeight ();
	void	Create (Decart place);
	void	Delete ();
	void	CountSpeed ();
};

struct Size
{
	int W;
	int H;
};

class ButtonInfo
{
public:
	int Top;
	int Bottom;
	int LSide;
	int RSide;
	ButtonInfo(int Top, int Bottom, int LSide, int RSide);
	~ButtonInfo();
};

MouseButtonType	CatchButton ();
double			getMinDistance (int a, int b);
void			CheckWindowPosition();
void			ClearScreen ();
void			Collide (const int &a, const int &b);
void			MouseAction (MouseButtonType Button);
void			SandBox (double Size);
void			UpdateTail (int N);
void			InitButtons (void);

const double	MaxObjectAccel = 3;
const double	MaxObjectSpeed = 500;
const double	MaxObjectWeight = 100;
const double	MaxZoom = 1;
const double	MinObjectWeight = 10;
const double	MinZoom = 0.05;
const double	PI = 3.14159265;
const int		AlertDuration = 3000;
const int		MaxCountingAcuracy = 100;
const int		MaxObjectSize = 30;
const int		MinCountingAcuracy = 2;
const int		ObjectAmount = 50;

AlertType		Alert = NoAlert;
Decart			Mouse;
Decart			Tr = Decart (0, 0); // translating matrix
ObjectInfo		Object[ObjectAmount];
Size			Win;
SkinType		Skin = Usual;
bool			FocusCurrentObject = false;
bool			Pause = false;
bool			ShowSettings = false;
bool			SpeedSetup = false;
bool			WeightSetup = false;
bool			WinPosSetup = false;
double			CollisionResistance = 0.0;
double			FPS = 30;
double			Resistance = 0.0;
double			SBS = 19.5; // SandBox Size
double			NavigationSpeed = 0.05;
double			SimulationSpeed = 5.0;
double			Zoom = 0.25;
int				AlertDelay = 0;
int				CountingAcuracy = 10;
int				CurrentObjectAmount = 0;
int				CurrentPressedButton;
int				EditObject = NoEditObject;
int				TailLenth = 5;
#endif